package com.ruoyi.wms.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wms.domain.WmsReceiptOrder;
import com.ruoyi.wms.service.IWmsReceiptOrderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;

/**
 * 收货订单Controller
 * 
 * @author ruoyi
 * @date 2024-01-01
 */
@Api(tags = "收货订单管理")
@RestController
@RequestMapping("/wms/receiptOrder")
public class WmsReceiptOrderController extends BaseController
{
    @Autowired
    private IWmsReceiptOrderService wmsReceiptOrderService;

    /**
     * 查询收货订单列表
     */
    @ApiOperation("查询收货订单列表")
    @PreAuthorize("@ss.hasPermi('wms:receiptOrder:list')")
    @GetMapping("/list")
    public TableDataInfo list(WmsReceiptOrder wmsReceiptOrder)
    {
        startPage();
        List<WmsReceiptOrder> list = wmsReceiptOrderService.selectWmsReceiptOrderList(wmsReceiptOrder);
        return getDataTable(list);
    }

    /**
     * 导出收货订单列表
     */
    @ApiOperation("导出收货订单列表")
    @PreAuthorize("@ss.hasPermi('wms:receiptOrder:export')")
    @Log(title = "收货订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WmsReceiptOrder wmsReceiptOrder)
    {
        List<WmsReceiptOrder> list = wmsReceiptOrderService.selectWmsReceiptOrderList(wmsReceiptOrder);
        ExcelUtil<WmsReceiptOrder> util = new ExcelUtil<WmsReceiptOrder>(WmsReceiptOrder.class);
        util.exportExcel(response, list, "收货订单数据");
    }

    /**
     * 获取收货订单详细信息
     */
    @ApiOperation("获取收货订单详细信息")
    @ApiImplicitParam(name = "orderId", value = "订单ID", required = true, dataType = "Long", paramType = "path")
    @PreAuthorize("@ss.hasPermi('wms:receiptOrder:query')")
    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") Long orderId)
    {
        return success(wmsReceiptOrderService.selectWmsReceiptOrderById(orderId));
    }

    /**
     * 根据订单编号获取收货订单详细信息
     */
    @ApiOperation("根据订单编号获取收货订单详细信息")
    @ApiImplicitParam(name = "orderNo", value = "订单编号", required = true, dataType = "String", paramType = "path")
    @PreAuthorize("@ss.hasPermi('wms:receiptOrder:query')")
    @GetMapping(value = "/orderNo/{orderNo}")
    public AjaxResult getInfoByOrderNo(@PathVariable("orderNo") String orderNo)
    {
        return success(wmsReceiptOrderService.selectWmsReceiptOrderByOrderNo(orderNo));
    }

    /**
     * 新增收货订单
     */
    @ApiOperation("新增收货订单")
    @PreAuthorize("@ss.hasPermi('wms:receiptOrder:add')")
    @Log(title = "收货订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WmsReceiptOrder wmsReceiptOrder)
    {
        return toAjax(wmsReceiptOrderService.insertWmsReceiptOrder(wmsReceiptOrder));
    }

    /**
     * 创建收货订单
     */
    @ApiOperation("创建收货订单")
    @PreAuthorize("@ss.hasPermi('wms:receiptOrder:add')")
    @Log(title = "收货订单", businessType = BusinessType.INSERT)
    @PostMapping("/create")
    public AjaxResult create(@RequestBody WmsReceiptOrder wmsReceiptOrder)
    {
        return toAjax(wmsReceiptOrderService.createReceiptOrder(wmsReceiptOrder));
    }

    /**
     * 修改收货订单
     */
    @ApiOperation("修改收货订单")
    @PreAuthorize("@ss.hasPermi('wms:receiptOrder:edit')")
    @Log(title = "收货订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WmsReceiptOrder wmsReceiptOrder)
    {
        return toAjax(wmsReceiptOrderService.updateWmsReceiptOrder(wmsReceiptOrder));
    }

    /**
     * 删除收货订单
     */
    @ApiOperation("删除收货订单")
    @ApiImplicitParam(name = "orderIds", value = "订单ID数组", required = true, dataType = "Long[]", paramType = "path")
    @PreAuthorize("@ss.hasPermi('wms:receiptOrder:remove')")
    @Log(title = "收货订单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{orderIds}")
    public AjaxResult remove(@PathVariable Long[] orderIds)
    {
        return toAjax(wmsReceiptOrderService.deleteWmsReceiptOrderByIds(orderIds));
    }

    /**
     * 收货确认
     */
    @ApiOperation("收货确认")
    @PreAuthorize("@ss.hasPermi('wms:receiptOrder:confirm')")
    @Log(title = "收货订单", businessType = BusinessType.UPDATE)
    @PostMapping("/confirm")
    public AjaxResult confirmReceipt(@RequestBody WmsReceiptOrder order)
    {
        return toAjax(wmsReceiptOrderService.confirmReceipt(order));
    }

    /**
     * 取消收货订单
     */
    @ApiOperation("取消收货订单")
    @ApiImplicitParam(name = "orderNo", value = "订单编号", required = true, dataType = "String", paramType = "path")
    @PreAuthorize("@ss.hasPermi('wms:receiptOrder:cancel')")
    @Log(title = "收货订单", businessType = BusinessType.UPDATE)
    @PutMapping("/cancel/{orderNo}")
    public AjaxResult cancelReceiptOrder(@PathVariable("orderNo") String orderNo)
    {
        return toAjax(wmsReceiptOrderService.cancelReceiptOrder(orderNo));
    }

    /**
     * 完成收货订单
     */
    @ApiOperation("完成收货订单")
    @ApiImplicitParam(name = "orderNo", value = "订单编号", required = true, dataType = "String", paramType = "path")
    @PreAuthorize("@ss.hasPermi('wms:receiptOrder:complete')")
    @Log(title = "收货订单", businessType = BusinessType.UPDATE)
    @PutMapping("/complete/{orderNo}")
    public AjaxResult completeReceiptOrder(@PathVariable("orderNo") String orderNo)
    {
        return toAjax(wmsReceiptOrderService.completeReceiptOrder(orderNo));
    }
}